home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C10 / StaticArray.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  869 b   |  38 lines

  1. //: C10:StaticArray.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Initializing static arrays
  7.  
  8. class Values {
  9.   // static consts can be initialized in-place:
  10.   static const int scSize = 100;
  11.   // Automatic counting works with static consts:
  12.   static const float scTable[] = {
  13.     1.1, 2.2, 3.3, 4.4
  14.   };
  15.   static const char scLetters[] = {
  16.     'a', 'b', 'c', 'd', 'e',
  17.     'f', 'g', 'h', 'i', 'j'
  18.   };
  19.   // Non-const statics must be 
  20.   // initialized externally:
  21.   static int size;
  22.   static float table[4];
  23.   static char letters[10];
  24. };
  25.  
  26. int Values::size = 100;
  27.  
  28. float Values::table[4] = {
  29.   1.1, 2.2, 3.3, 4.4
  30. };
  31.  
  32. char Values::letters[10] = {
  33.   'a', 'b', 'c', 'd', 'e',
  34.   'f', 'g', 'h', 'i', 'j'
  35. };
  36.  
  37. int main() { Values v; } ///:~
  38.